/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package src;

import java.sql.*;


public class DBManager extends Object {

   public Connection conn;
   public Statement stmt;
   public PreparedStatement pstmt;
   public ResultSet rset;
   //jdbc:oracle:thin:@192.168.1.5:1521:XE [koperasi on KOPERASI]
   private String url = "jdbc:oracle:thin:@192.168.1.5:1521:XE";
   private String db = "";
   private String driver = "oracle.jdbc.OracleDriver";
   private String user = "koperasi";
   private String pass = "adm";
      
   public DBManager() {
      conn = null;
      
  /*    try {
         Class.forName(driver).newInstance();
         conn = DriverManager.getConnection(url + db, user, pass);
      } catch (Exception e) {
         throw new RuntimeException(e.getMessage());
      }*/
   }
   
   public void getConnection(){
      try {
         Class.forName(driver).newInstance();
         conn = DriverManager.getConnection(url + db, user, pass);
      } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
         throw new RuntimeException(e.getMessage());
      }  
   }
   
   public void putConnection(){
      try {
       if (stmt!= null)
           stmt.close();
       if (pstmt!= null)
           pstmt.close();
       if (conn != null)  
            conn.close();
       } catch (Exception e) {
         throw new RuntimeException(e.getMessage());
      } 
   }
}
